var vm = new Vue({
    el: '#app',
    data: {
        articleId: '',
        content_html: '',
        content_md: '',
        title: '',
        tags: '',
        content_abstract: '',
        gmtModify: '',
        gmtCreate: '',
        editorConfig: '',

        resMsg: '',
        button_html: '保存'
    },
    methods: {
        initEditor: function () {
            //  默认请求 地址
            $.get(baseURL + '/article/getDemo', function (md) {
                vm.editorConfig = editormd("editor_article", {
                    autoHeight: true,
                    width: "95%",
                    height: 7400,
                    path: '/lucode-for-all-web/common/markdown/lib/',
                    theme: "default",
                    previewTheme: "default",
                    editorTheme: "default",
                    markdown: md.contentMd,
                    codeFold: true,
                    syncScrolling : false,
                    saveHTMLToTextarea: true,    // 保存 HTML 到 Textarea
                    searchReplace: true,
                    htmlDecode: "style,script,iframe|on*",            // 开启 HTML 标签解析，为了安全性，默认不开启
                    emoji: true,
                    taskList: true,
                    tocm: true,         // Using [TOCM]
                    tex: true,                   // 开启科学公式TeX语言支持，默认关闭
                    flowChart: true,             // 开启流程图支持，默认关闭
                    sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
                    toolbarIcons: function () {
                        return ["undo", "redo", "bold", "del", "italic", "|",
                            "quote", "uppercase", "list-ul", "list-ol", "|",
                            "hr", "link", "reference-link", "code", "|",
                            "preformatted-text", "code-block", "table", "datetime", "emoji", "|",
                            "html-entities", "pagebreak", "watch", "|",
                            "fullscreen", "help", "info"];
                    }
                });
            });
        },
        save: function () {
            vm.resMsg='';
            var url = baseURL + "/article/saveOrUpdate";
            vm.content_html = vm.editorConfig.getHTML();
            vm.content_md = vm.editorConfig.getMarkdown();
            vm.button_html = '<i class=\"am-icon-spinner am-icon-spin\"></i>请稍等';

            $.post(url,
                {
                    contentHtml: vm.content_html,
                    contentMd: vm.content_md,
                    title: vm.title
                },
                function (data, status) {
                    if (data.resCode === "9999") {
                        vm.articleId = data.articleId;
                        vm.resMsg = success_alter_html;
                        vm.button_html = '更新';
                    } else {
                        vm.resMsg = "<div class=\"am-alert am-alert-danger\" data-am-alert>" +
                            "<button type=\"button\" class=\"am-close\">&times;</button>" +
                            "<p>" +data.resCode + " " + data.resMsg+"</p>"+
                            "</div>";
                        vm.button_html = '保存';
                    }
                });
        },
        update: function () {
            vm.resMsg='';
            vm.successAlter = false;
            vm.errorAlter = false;
            var url = baseURL + "/article/saveOrUpdate";
            vm.content_html = vm.editorConfig.getHTML();
            vm.content_md = vm.editorConfig.getMarkdown();
            vm.button_html = '<i class=\"am-icon-spinner am-icon-spin\"></i>请稍等';
            $.post(url,
                {
                    articleId:vm.articleId,
                    contentHtml: vm.content_html,
                    contentMd: vm.content_md,
                    title: vm.title
                },
                function (data, status) {
                    if (data.resCode === "9999") {
                        vm.resMsg = success_alter_html;
                        vm.button_html = '更新';
                    } else {
                        vm.resMsg = "<div class=\"am-alert am-alert-danger\" data-am-alert>" +
                            "<button type=\"button\" class=\"am-close\">&times;</button>" +
                            "<p>" +data.resCode + " " + data.resMsg+"</p>"+
                            "</div>";
                        vm.button_html = '更新';
                    }
                });
        }

    },
    created: function () {
        this.initEditor();
    }

});
